<?php

namespace App\Http\Controllers\Url;

use App\AppChannel;
use App\BlackAccessLog;
use App\Http\Controllers\Controller;
use App\ReferBlackUrl;
use App\Services\UrlService;
use App\UserApp;
use Jenssegers\Agent\Agent;

/**
 * Class UrlController
 *
 * @package \App\Http\Controllers\Url
 */
class UrlController extends Controller
{

    /**
     * @param $keyword
     *
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */
    public function index($keyword) {
        if (empty($keyword)) {
            return abort(404);
        }

        // 获取referer 正常读取http的
        $referer = request()->server('HTTP_REFERER');

        if (empty($referer)) {
            // 获取https的 refer
            $referer = request("refer", '');
        }

        $source = request()->get("source", '');
        $ip = request()->getClientIp();

        $service = new UrlService();
        $data = $service->doParse($keyword, $referer, $source, $ip);


        if (empty($data)) {
            return abort(404);
        }

        return view("url.index", $data);
    }
}
